package gui;

import helden.plugin.werteplugin2.PluginHeld2;

import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JComboBox;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.JButton;

import main.Controller;

/**
 * 
 * @author Christian
 * @since 0.15d
 */
public class HeldenUpdatePanel extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 
	 */
	private JComboBox jComboBox = null;
	
	/**
	 * 
	 */
	private JLabel jLabel = null;
	
	/**
	 * 
	 */
	private JPanel jPanel = null;
	
	/**
	 * 
	 */
	private JButton jZurueckButton = null;
	
	/**
	 * 
	 */
	private JButton jWeiterButton = null;
	
	/**
	 * This method initializes
	 * 
	 */
	public HeldenUpdatePanel() {

		super();
		initialize();
	}
	
	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {

		GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
		gridBagConstraints9.gridx = 0;
		gridBagConstraints9.insets = new Insets(5, 5, 5, 5);
		gridBagConstraints9.gridy = 2;
		GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
		gridBagConstraints8.gridx = 0;
		gridBagConstraints8.gridy = 0;
		gridBagConstraints8.insets = new Insets(5, 5, 5, 5);
		jLabel = new JLabel();
		jLabel.setText("Helden auswählen");
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.weightx = 1.0;
		this.setLayout(new GridBagLayout());
		this.setSize(new Dimension(271, 178));
		this.add(getJComboBox(), gridBagConstraints);
		this.add(jLabel, gridBagConstraints8);
		this.add(getJPanel(), gridBagConstraints9);
	}
	
	/**
	 * This method initializes jComboBox
	 * 
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getJComboBox() {

		if (jComboBox == null) {
			jComboBox = new JComboBox();
		}
		jComboBox.removeAllItems();
		for (PluginHeld2 held : Controller.getDatenController().getHelden()) {
			jComboBox.addItem(held);
		}
		jComboBox.setSelectedIndex(0);
		return jComboBox;
	}
	
	/**
	 * This method initializes jPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanel() {

		if (jPanel == null) {
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints2.gridy = 2;
			gridBagConstraints2.gridx = 1;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.insets = new Insets(5, 5, 5, 5);
			gridBagConstraints1.gridy = 2;
			gridBagConstraints1.gridx = 0;
			jPanel = new JPanel();
			jPanel.setLayout(new GridBagLayout());
			jPanel.add(getJZurueckButton(), gridBagConstraints1);
			jPanel.add(getJWeiterButton(), gridBagConstraints2);
		}
		return jPanel;
	}
	
	/**
	 * This method initializes jZurueckButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJZurueckButton() {

		if (jZurueckButton == null) {
			jZurueckButton = new JButton();
			jZurueckButton.setText("zurück");
			jZurueckButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {

					Controller.getGuiController().zeigeHauptfenster();
				}
			});
		}
		return jZurueckButton;
	}
	
	/**
	 * This method initializes jWeiterButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJWeiterButton() {

		if (jWeiterButton == null) {
			jWeiterButton = new JButton();
			jWeiterButton.setText("weiter");
			jWeiterButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {

					PluginHeld2 held = (PluginHeld2) jComboBox.getSelectedItem();
					if (held.hatZaubersprueche()) {
						Controller.getGuiController().zeigeHeldenUpdateZauber(held, 0);
					} else {
						jLabel.setText("Dieser Held kann nicht Zaubern!");
					}
				}
			});
		}
		return jWeiterButton;
	}
} // @jve:decl-index=0:visual-constraint="10,10"
